﻿using System;
using System.Text;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdateFileCommand : WindowsLiveCommand
    {
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ObjectID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public override string GraphApiPath
        {
            get
            {
                return this.ObjectID;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override HttpMethodName MethodName
        {
            get
            {
                return HttpMethodName.Put;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objectID">オブジェクトのID (例:FILE_ID、PHOTO_ID、FOLDER_ID、AUDIO_ID、VIDEO_ID、ALBUM_ID)</param>
        public UpdateFileCommand(String objectID)
        {
            this.ObjectID = objectID;
            this.ContentType = "application/json";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override byte[] SetData()
        {
            if ((Name == null) && (Description == null))
                throw new ArgumentNullException("Parameter is error!");

            StringBuilder s = new StringBuilder();
            s.AppendLine("{");
            if (!HttpClient.IsNullOrWhiteSpace(Name))
                s.AppendFormat("name: \"{0}\"", Name);
            if (Description != null)
            {
                if (Name != null) 
                    s.Append(",\r\n");
                s.AppendFormat("description: \"{0}\"", Description);
            }
            s.AppendLine("\r\n}");

            return Encoding.UTF8.GetBytes(s.ToString());
        }
    }
}
